/**
 * 排序封装类
 */
package com.eight.pageInfo;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

/**
 * <p>Company: B505信息技术研究所 </p> 
 * @Description: 排序封装类
 * @Create Date: 2017年11月26日上午11:30:21
 * @Version: V1.00 
 * @Author: yulin
 */
@Component
public class SortTools {
	
	public Sort basicSort() {
        return basicSort("desc", "id");
    }

    public Sort basicSort(String orderType, String orderField) {
        Sort sort = new Sort(Sort.Direction.fromString(orderType), orderField);
        return sort;
    }

    public  Sort basicSort(SortDto... dtos) {
    	Sort result = null;
        for(int i=0; i<dtos.length; i++) {
            SortDto dto = dtos[i];
            if(result == null) {
                result = new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField());
            } else {
                result = result.and(new Sort(Sort.Direction.fromString(dto.getOrderType()), dto.getOrderField()));
            }
        }
        return result;
    }
}
